import { reactive, toRefs } from 'vue'

import { codeMaps, getByDictCodeList } from '@/api/backend/dict'
import { getToday } from '@/api/help'

import IBaseObj from '#/index'

const commonState: IBaseObj = reactive({
  passOptions: [],
  priorityOptions: [],
})

const getDictData = async () => {
  const ret = await getByDictCodeList([codeMaps.pass, codeMaps.priority])
  commonState.passOptions = ret[codeMaps.pass]
  commonState.priorityOptions = ret[codeMaps.priority]
}

const getTodayTime = async () => {
  const ret = await getToday()
  return ret.data
}

export default {
  ...toRefs(commonState),
  getDictData,
  getTodayTime,
} as IBaseObj

// export const useState = () => {
//   const state: IBaseObj = reactive({
//     form: {
//       pass: '',
//       priority: '',
//       beginTime: '',
//       endTime: ''
//     },
//     canEdit: false,

//   })

//   return {
//     ...toRefs(state),
//     getDictData,
//     getTodayTime
//   } as IBaseObj
// }
